// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程：https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129
const db = uniCloud.database();
const cmd = db.command;
module.exports = {
	_before: function() { // 通用预处理器
		this.params = this.getParams()[0];
	},
	async add() {
		this.params.checked = false;
		return await db.collection("mall-sku").add(this.params);
	},
	async get() {
		return await db.collection("mall-sku").get();
	},
	async update() {
		let params = {
			...this.params
		};
		delete params._id;
		return await db.collection("mall-sku").doc(this.params._id).update(params);
	},
	async updateSkuChild(id, obj) {
		obj.checked = false;
		return await db.collection("mall-sku").doc(id).update({
			children: cmd.push(obj)
		});
	}


}